home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / menu-new.tar / menu-new / menu / string.c < prev    next >
C/C++ Source or Header  |  1993-04-08  |  2KB  |  108 lines

  1.  
  2. # include <stdio.h>
  3. # include <ctype.h>
  4. # include <math.h>
  5.  
  6. # define TRUE 1
  7. # define FALSE 0
  8.  
  9. read_input(string)
  10. char *string;
  11. {                /* Read input into an array */
  12.     while((*string = getchar()) != '\n'){
  13.        *string++;
  14.     }
  15.     *string = '\0';
  16. }
  17.  
  18. read_str1(string)    /* Read a string if you are not in raw mode */
  19. char *string;
  20. {
  21.     char *str;
  22.  
  23.     no_echo();
  24.     cbreak();
  25.     str = string;
  26.     while((*str = getchar()) != '\n'){
  27.        if(*str ==  0x08  || *str == 0x7f)
  28.           if(*str != *string){
  29.          outc(0x08);
  30.          outc(0x20);
  31.          outc(0x08);
  32.          *str--;
  33.           }else
  34.          continue;
  35.        else{
  36.           outc(*str);
  37.           *str++;
  38.        }
  39.     }
  40.     *str = '\0';
  41.     echo();
  42.     cbreak();
  43. }
  44.  
  45. chop_str(string)
  46. char *string;
  47. {
  48.     int length;
  49.     
  50.     length = strlen(string);
  51.     while(*string != '\0')
  52.        *string++;
  53.     for(i=length;i>70;i--,*string--)
  54.       *string = '\0';
  55. }
  56.  
  57. char *str_pre_blank(string)
  58. char *string;
  59. {                /* Strip off preceding Blanks */
  60.     while(*string == ' ')
  61.        *string++;
  62.     return(string);
  63. }
  64.  
  65. str_trl_blank(string)
  66. char *string;            /* Strip Blanks from end of line */
  67. {
  68.     while(!isspace(*string))
  69.        *string++;
  70.     *string = '\0';
  71. }
  72.  
  73. int is_integer(string)
  74. char *string;            /* Is the string an integer?  */
  75. {
  76.     if((strlen(string)) == 0)
  77.       return(FALSE);
  78.     if(*string == '-')
  79.       *string++;
  80.     for(;*string != '\0'; *string++)
  81.         if(!isdigit(*string))
  82.            return(FALSE);
  83.     return(TRUE);
  84. }
  85.  
  86. int is_float(string)
  87. char *string;            /* Is the string a floating point number? */
  88. {                /* Invalid: (.),(.0),(1.0.) any string    */
  89.     int flag = FALSE;    /* containing a non-digit.          */
  90.  
  91.     if((strlen(string)) == 0)
  92.        return(FALSE);
  93.     if(!isdigit(*string) && *string != '-')
  94.        return(FALSE);
  95.     else
  96.        *string++;
  97.     for(;*string != '\0'; *string++){
  98.        if(!isdigit(*string) && *string != '.')
  99.          return(FALSE);
  100.        if(*string == '.' && flag == TRUE)
  101.          return(FALSE);
  102.        if(*string == '.')
  103.           flag = TRUE;
  104.     }
  105.     return(TRUE);
  106. }
  107.  
  108.